package hardcode2013;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;

public class Crypto {
	public static String SHA1Encrypt(String value) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			return byteArray2Hex(md.digest(value.getBytes()));
		} catch (NoSuchAlgorithmException e) {
			return null;
		}	    
	}

	private static String byteArray2Hex(final byte[] hash) {
	    Formatter formatter = new Formatter();
	    for (byte b : hash)
	        formatter.format("%02x", b);
	    String res = formatter.toString();
	    formatter.close();
	    return res;
	}
}
